package com.hyf.serviceedu.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyf.commonutils.fruit;
import com.hyf.serviceedu.entity.EduCourse;
import com.hyf.serviceedu.entity.EduTeacher;
import com.hyf.serviceedu.service.EduCourseService;
import com.hyf.serviceedu.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(description="前端教师接口")
@RestController
@RequestMapping("/serviceedu/eduteacher")
public class TecherfromController {

	@Autowired// 前端讲师接口
	private EduTeacherService eduTeacherService;
	
	
	
	@Autowired// 课程信息
	private EduCourseService eduCourseService;
	
	// 前端分页查询讲师
	@ApiOperation(value = "前端分页讲师列表")
	@GetMapping(value = "getTeacherFrontList/{page}/{limit}")
	public fruit pageList(
		@ApiParam(name = "page", value = "当前页码", required = true)
		@PathVariable Long page,
		@ApiParam(name = "limit", value = "每页记录数", required = true)
		@PathVariable Long limit){
		
		Page<EduTeacher> pageParam = new Page<EduTeacher>(page, limit);
		
		Map<String, Object> map = eduTeacherService.getTeacherFromtList(pageParam);
		
		return  fruit.ok().data(map);
	}
	
	
	
	//根据ID查询讲师 讲师详情列表
	@ApiOperation(value = "根据ID查询讲师")
	@GetMapping(value = "{id}")
	public fruit getById(
        @ApiParam(name = "id", value = "讲师ID", required = true)
		@PathVariable String id){
		//查询讲师信息
		EduTeacher teacher = eduTeacherService.getById(id);
		
		//根据讲师id查询这个讲师的课程列表
		
		List<EduCourse> courseList = eduCourseService.selectByTeacherId(id);
		
		return fruit.ok().data("teacher", teacher).data("courseList", courseList);
		
	}

}
